/*
 *      SymEntry.java
 *
 *      Copyright 2008 Pablo Nicolas Diaz Bilotto <pablonicolas.diaz@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */
package symbolStorageService;

import lexer.EntryType;
import lexer.token.TokenEnum;


/**
 * The Class SymEntry.
 */
public class SymEntry implements ISymEntry {

	/** The LN. */
	private int LN;

	/** The my kind. */
	private TokenEnum myKind;

	/** The my type. */
	private EntryType myType;

	/** The Used. */
	private boolean Used;

	/** The Initial value. */
	private Object InitialValue = "?";

	/**
	 * Instantiates a new sym entry.
	 *
	 * @param LN
	 *            the lN
	 * @param myKind
	 *            the my kind
	 * @param myType
	 *            the my type
	 * @param used
	 *            the used
	 * @param InValue
	 *            the in value
	 */
	public SymEntry(int LN, TokenEnum myKind, EntryType myType, boolean used,
			Object InValue) {
		setUsed(used);
		this.LN = LN;
		this.myKind = myKind;
		this.setType(myType);
		this.setInitialValue(InValue);
	}

	/**
	 * Instantiates a new sym entry.
	 *
	 * @param LN
	 *            the lN
	 * @param myKind
	 *            the my kind
	 * @param myType
	 *            the my type
	 * @param InValue
	 *            the in value
	 */
	public SymEntry(int LN, TokenEnum myKind, EntryType myType, Object InValue) {
		this(LN, myKind, myType, false, InValue);
	}

	/**
	 * Gets the initial value.
	 *
	 * @return the initial value
	 */
	public Object getInitialValue() {
		return InitialValue;
	};

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#getKind()
	 */
	public TokenEnum getKind() {
		return myKind;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#getLineNumber()
	 */
	public int getLineNumber() {
		return this.LN;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#getType()
	 */
	public EntryType getType() {
		return myType;
	};

	/*
	 * (non-Javadoc)
	 *
	 * @see symbolStorageService.ISymEntry#isKeyword()
	 */
	@Override
	public boolean isKeyword() {
		return this.LN == 0;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#isTyped()
	 */
	public boolean isTyped() {

		return !(this.getKind() == TokenEnum.IDENTIFIER && this.getType() == EntryType.NOTYPE);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#isUsed()
	 */
	public boolean isUsed() {
		return Used;
	}

	/**
	 * Sets the initial value.
	 *
	 * @param initialValue
	 *            the new initial value
	 */
	public void setInitialValue(Object initialValue) {
		InitialValue = initialValue;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#setType(lexer.EntryType)
	 */
	public void setType(EntryType myType) {
		this.myType = myType;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see symbol_storage_service.ISymEntry#setUsed(boolean)
	 */
	public void setUsed(boolean used) {
		Used = used;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		/*
		 * String US=" "; if (!this.Used) US=" NOT USED!"; String DC=" "; if
		 * (!this.isTyped()) DC=" NOT TYPED!";
		 */
		return this.myType.toString() + " " + this.InitialValue.toString();

	}
	public String  toGui() {
		return "Type => " + this.myType.toGui() + " ; Initial Value => " + this.InitialValue.toString();
	}

}
